package com.csg.ses.controller;

import com.csg.ses.common.annotation.LoginToken;
import com.csg.ses.entity.ses.SysOrganizationEntity;
import com.csg.ses.service.ses.SysOrganizationService;
import com.csg.ses.vo.common.OrgVo;
import com.csg.ses.vo.common.Result;
import com.csg.ses.vo.common.ResultStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 组织
 * @author cjj
 * @date 2021/03/03
 */
@RestController
@RequestMapping("/org")
@Api(tags = "组织接口")
@ApiIgnore
public class SysOrganizationController {
    @Autowired
    private SysOrganizationService sysOrganizationService;

    /**
     * 列表
     */
    @ApiOperation(value = "组织")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "org", value = "组织信息", dataType = "SysOrganizationEntity", paramType = "body"),
        @ApiImplicitParam(name = "current", value = "当前页", required = true ,dataType = "Integer"),
        @ApiImplicitParam(name = "size", value = "每页记录数", required = true ,dataType = "Integer")
    })
    @GetMapping("/list")
    @LoginToken
    public Result<List<SysOrganizationEntity>> list(SysOrganizationEntity org, Long current, Long size) {
        return sysOrganizationService.retrieve(org, current, size);
    }

    @ApiOperation(value = "组织机构下拉树")
    @GetMapping("/tree")
    @LoginToken
    public Result<List<OrgVo>> tree() {
        return new Result(sysOrganizationService.tree(), ResultStatus.SUCCESS);
    }

    @ApiOperation(value = "根据id查找组织")
    @ApiImplicitParam(name = "id", value = "组织id", dataType = "String", required = true)
    @GetMapping("/{id}")
    @LoginToken
    public Result<SysOrganizationEntity> getById(@PathVariable String id) {
        return sysOrganizationService.getById(id);
    }
}